package com.ajavaer.framework.pay.response;

import com.ajavaer.framework.pay.request.WeixinPayRequest;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.wxpay.sdk.WXPayConstants;
import com.github.wxpay.sdk.WXPayUtil;

import java.util.HashMap;
import java.util.Map;

public class WeixinPaySignResponse implements WeixinPayRequest {
    private WXPayConstants.SignType signType = WXPayConstants.SignType.HMACSHA256;

    public WeixinPaySignResponse(String appId) {
        this.appId = appId;
    }

    @Override
    public Map<String, String> toMap() {
        if (prepay_id == null) {
            throw new RuntimeException("prepay_id 不能为空");
        }
        Map<String, String> map = new HashMap<>();
        map.put("appId", appId);
        map.put("timeStamp", timeStamp);
        map.put("nonceStr", nonceStr);
        String packValue = "prepay_id=" + prepay_id;
        map.put("package", packValue);
        set_package(packValue);
        map.put("signType", signType.name());
        return map;
    }

    private String timeStamp = WXPayUtil.getCurrentTimestamp() + "";

    private String nonceStr = WXPayUtil.generateNonceStr();

    @JsonProperty(value = "package")
    private String _package;


    private String paySign;

    private String prepay_id;

    /**
     * 小程序appId
     */
    private String appId;

    /**
     * 返回业务信息数据
     */
    private Object target;

    public String getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(String timeStamp) {
        this.timeStamp = timeStamp;
    }

    public String getNonceStr() {
        return nonceStr;
    }

    public void setNonceStr(String nonceStr) {
        this.nonceStr = nonceStr;
    }

    public String get_package() {
        return _package;
    }

    public void set_package(String _package) {
        this._package = _package;
    }

    public WXPayConstants.SignType getSignType() {
        return signType;
    }

    public void setSignType(WXPayConstants.SignType signType) {
        this.signType = signType;
    }

    public String getPaySign() {
        return paySign;
    }

    public void setPaySign(String paySign) {
        this.paySign = paySign;
    }

    public String getPrepay_id() {
        return prepay_id;
    }

    public void setPrepay_id(String prepay_id) {
        this.prepay_id = prepay_id;
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public Object getTarget() {
        return target;
    }

    public void setTarget(Object target) {
        this.target = target;
    }
}
